package com.ruoyi.point.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.point.pojo.SessionPermissions;
import com.ruoyi.point.service.ISessionPermissionsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记录权杖人员Controller
 *
 * @author ruoyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/system/permissions")
public class SessionPermissionsController extends BaseController
{
    @Autowired
    private ISessionPermissionsService sessionPermissionsService;

    /**
     * 查询记录权杖人员列表
     */
    @PreAuthorize("@ss.hasRole('admin')")
    @GetMapping("/list")
    public TableDataInfo list(SessionPermissions sessionPermissions)
    {
        startPage();
        List<SessionPermissions> list = sessionPermissionsService.selectSessionPermissionsList(sessionPermissions);
        return getDataTable(list);
    }

    /**
     * 导出记录权杖人员列表
     */
    @PreAuthorize("@ss.hasPermi('system:permissions:export')")
    @Log(title = "记录权杖人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SessionPermissions sessionPermissions)
    {
        List<SessionPermissions> list = sessionPermissionsService.selectSessionPermissionsList(sessionPermissions);
        ExcelUtil<SessionPermissions> util = new ExcelUtil<SessionPermissions>(SessionPermissions.class);
        util.exportExcel(response, list, "记录权杖人员数据");
    }

    /**
     * 获取记录权杖人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:permissions:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sessionPermissionsService.selectSessionPermissionsById(userId));
    }

    /**
     * 新增记录权杖人员
     */
    @PreAuthorize("@ss.hasPermi('system:permissions:add')")
    @Log(title = "记录权杖人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SessionPermissions sessionPermissions)
    {
        return toAjax(sessionPermissionsService.insertSessionPermissions(sessionPermissions));
    }

    /**
     * 修改记录权杖人员
     */
    @PreAuthorize("@ss.hasPermi('system:permissions:edit')")
    @Log(title = "记录权杖人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SessionPermissions sessionPermissions)
    {
        return toAjax(sessionPermissionsService.updateSessionPermissions(sessionPermissions));
    }

    /**
     * 删除记录权杖人员
     */
    @PreAuthorize("@ss.hasPermi('system:permissions:remove')")
    @Log(title = "记录权杖人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sessionPermissionsService.deleteSessionPermissionsByUserIds(userIds));
    }
}
